package general;

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Class for inserting log faculty in work with configuration
 * 
 * @author Last G
 */
public class LoggableProperties extends Properties
{

	/**
	 * Serialization number
	 */
	private static final long serialVersionUID = -7372657019304150335L;
	private static final Logger logger = LoggerFactory
			.getLogger(LoggableProperties.class);
	private Properties _default;

	/**
	 * @see Properties
	 */
	public LoggableProperties()
	{
		super();
		logger.trace("Created");
	}
	/**
	 * @param _default default properties
	 * @see Properties
	 */
	public LoggableProperties(Properties _default)
	{
		super();
		this._default = _default;
		logger.trace("Created with defaults");
	}

	@Override
	public String getProperty(String key)
	{
		logger.trace("getProperty invoked with '{}' key", key);
		String result = super.getProperty(key);
		if (result == null)
		{
			result = _default.getProperty(key);
			if (result != null)
			{
				logger.warn(
						"Using default property value '{}' for '{}' property",
						result, key);
			}
		}

		logger.trace("getProperty ends");
		return result;
	}
}
